package com.pro.controller;

import com.pro.pojo.JsLog;
import com.pro.pojo.JsonData;
import com.pro.service.JsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods/log")
public class JsLogController {

    @Autowired
    private JsLogService jsLogService;

    /**
     * 表格的查询
     * @param id 模糊查id
     * @param name 模糊查name
     * @param time 模糊查time
     * @return
     */
    @RequestMapping("getLogList")
    @ResponseBody
    public JsonData getLogList(String id, String name, String time, Integer limit, Integer page){
        id = id != null ? "%"+id+"%":"%%";
        name = name != null ? "%"+name+"%":"%%";
        time = time != null ? "%"+time+"%":"%%";
        page = (page - 1) * limit;
        List<JsLog> logList = jsLogService.getLogList(id, name, time,limit,page);
        Integer count = jsLogService.getLogListCount(id, name, time);
        return logList !=null ? JsonData.buildSuccess(logList,count): JsonData.buildError("服务端错误");
    }

    /**
     * 通过id删除此数据
     * @param id
     * @return
     */
    @RequestMapping("removeLogById")
    @ResponseBody
    public JsonData removeLogById(Integer id){
        Integer i = jsLogService.removeLogById(id);
        return i > 0 ? JsonData.buildSuccess(i): JsonData.buildError("服务端错误");
    }

}
